From c4865bed432073ff8ed0551e16169c57f5633b32 Mon Sep 17 00:00:00 2001 From: Daniel Boles Date: Mon, 7 Aug 2017 18:25:28 +0100 Subject: [PATCH] Container: Fix scrolled coord in set_focus_child() Commit 885bcd9fe4b6b4ecb003570ea0520cf42ec737a9 trampled the bit here that is meant to translate between the nominated focus child and the actual innermost one that is used for updating the h/v adjustments. So, we need to save the passed focus child before diving into its children, then translate and get allocations between them both. This makes GTK+ 4 behave like GTK+ 3 again: instead of priv->focus_child and focus_child, we now have focus_child and child, serving the roles of the nominated focus child and its innermost focus child respectively. This also ditches the unnecessary call to Widget:get_focus_child(), as Container::set_focus_child() gets that same new child as an argument. --- gtk/gtkcontainer.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/gtk/gtkcontainer.c b/gtk/gtkcontainer.c index 0a2dbf9aec..bc52c99554 100644 --- a/gtk/gtkcontainer.c +++ b/gtk/gtkcontainer.c @@ -2032,15 +2032,11 @@ gtk_container_compute_expand (GtkWidget *widget, } static void -gtk_container_real_set_focus_child (GtkContainer *container, - GtkWidget *child) +gtk_container_real_set_focus_child (GtkContainer *container, + GtkWidget *focus_child) { - GtkWidget *focus_child; - g_return_if_fail (GTK_IS_CONTAINER (container)); - g_return_if_fail (child == NULL || GTK_IS_WIDGET (child)); - - focus_child = gtk_widget_get_focus_child (GTK_WIDGET (container)); + g_return_if_fail (focus_child == NULL || GTK_IS_WIDGET (focus_child)); /* check for h/v adjustments */ @@ -2055,17 +2051,19 @@ gtk_container_real_set_focus_child (GtkContainer *container, vadj = g_object_get_qdata (G_OBJECT (container), vadjustment_key_id); if (hadj || vadj) { - while (gtk_widget_get_focus_child (focus_child)) - focus_child = gtk_widget_get_focus_child (focus_child); + GtkWidget *child = focus_child; + + while (gtk_widget_get_focus_child (child)) + child = gtk_widget_get_focus_child (child); - gtk_widget_translate_coordinates (focus_child, focus_child, + gtk_widget_translate_coordinates (child, focus_child, 0, 0, &x, &y); _gtk_widget_get_allocation (focus_child, &allocation); x += allocation.x; y += allocation.y; - _gtk_widget_get_allocation (focus_child, &allocation); + _gtk_widget_get_allocation (child, &allocation); if (vadj) gtk_adjustment_clamp_page (vadj, y, y + allocation.height); -- 2.30.2